/// @tags: DP
#include <algorithm>
#include <cstdio>
#include <iostream>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 3e3 + 1;

struct Object {
  int w, r;
  bool operator<(const Object& rhs) const { return r > rhs.r; }
} objects[maxn];

int f[maxn][maxn];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> objects[i].w >> objects[i].r;
  }
  std::sort(objects + 1, objects + n + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= i; ++j) {
      f[i][j] = std::max(f[i - 1][j], f[i - 1][j - 1] + objects[i].w - (j - 1) * objects[i].r);
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; ++i) ans = std::max(ans, f[n][i]);
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P2647 最大收益.in", "r", stdin);
  freopen("P2647 最大收益.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  return BlueQuantum::main();
}
